<!DOCTYPE html> 
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hello, World</title>
<style type="text/css">html{height:100%}body{height:100%;margin:0px;padding:0px}#container{height:100%}</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=kYNBHZVjWZTHtx7d0itDoZUb"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
var gpstime;
var car;
var label;
var now=0;
var pArr=[];
var Coordinates=[];
var CoordinatesArr;
var map = new BMap.Map("container");
initMapOnCompsite();
function initMapOnCompsite(){
	var point = new BMap.Point(104.072227, 30.663468);  //初始位置 ,
	map.centerAndZoom(point, 16);
}

function gcj02ToBD09(lng,lat,sendtime) {
	setGpstime(sendtime);
	Coordinates[0]=lng;
	Coordinates[1]=lat;
	BMap.Convertor.translate(new BMap.Point(Coordinates[0],Coordinates[1]),2,translateCallback);
	now++;
}
function setGpstime(sendgpstime) {   
	gpstime = new Date(parseInt(sendgpstime) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");    
} 
function translateCallback(point){
	pArr.push(point);
	setTimeout("makeTrace()", 200);
}
function makeTrace() {
	map.removeOverlay(car);
	centerPoint = new BMap.Point(pArr[now-1].lng, pArr[now-1].lat);
	var xx=pArr[now-1].lng;
	var yy=pArr[now-1].lat;
	label = new BMap.Label("", {offset: new BMap.Size(-50, -50)});
	car = new BMap.Marker(centerPoint);
	car.setLabel(label);
	map.addOverlay(car);
	map.centerAndZoom(centerPoint, 16);
	map.addControl(new BMap.MapTypeControl());
	var polyline = new BMap.Polyline(pArr, {strokeColor:"green", strokeWeight:4, strokeOpacity:1});
	map.addOverlay(polyline);
	label.setContent("经度: " + xx.toFixed(6) + "<br>纬度: " + yy.toFixed(6) + "<br>GPS时间: " + gpstime);
	car.setPosition(pArr);
}
</script>
</body>
</html>